local util = require( 'utils' )

local SPEEDUPITEM = { 
	_nSpeedUp = 0,
	_paddle = nil,
	_normalState = nil,
	_actState = nil }

local sheetData = {}
sheetData.frames = {
	{
		x = 0,
		y = 0,
		width = 20,
		height = 20,
	},

	{
		x = 20,
		y = 0,
		width = 20,
		height = 20,
	},
}

function SPEEDUPITEM:newItem( g, d, parent, o )
	o = o or {}
	setmetatable(o, self)
	self.__index = self

	local options = {
		frames = sheetData.frames
	}

	local imageSheet = g.newImageSheet( 'speed-up.png', options )
	local normalState = { name="normal", start=1, count=1, time=1000 }
	local actState = { name="act", start=2, count=1, time=1000 }

	o._normalState = d.newSprite( parent, imageSheet, normalState )
	o._actState = d.newSprite( parent, imageSheet, actState )

	return o
end

function SPEEDUPITEM:move( x, y )
	self._actState.x = x
	self._normalState.x = x
	self._actState.y = y
	self._normalState.y = y
end

function SPEEDUPITEM:stand()
	self._normalState.isVisible = true
	self._normalState:play()

	self._actState.isVisible = false
	self._actState:pause()
end

function SPEEDUPITEM:hitted()
	self._actState.isVisible = true
	self._actState:play()

	self._normalState.isVisible = false
	self._normalState:pause()
end

function SPEEDUPITEM:getNSpeedUp()
	return self._nSpeedUp
end

function SPEEDUPITEM:setNSpeedUp( n )
	self._nSpeedUp = n
end

function SPEEDUPITEM:getPaddle()
	return self._paddle
end

function SPEEDUPITEM:setPaddle( paddle )
	self._paddle = paddle
end

function SPEEDUPITEM:getLeft()
	return util:getLeft( self._normalState )
end

function SPEEDUPITEM:getRight()
	return util:getRight( self._normalState )
end

function SPEEDUPITEM:getTop()
	return util:getTop( self._normalState )
end

function SPEEDUPITEM:getBottom()
	return util:getBottom( self._normalState )
end

function SPEEDUPITEM:getWidth()
	return self._normalState.contentWidth
end

function SPEEDUPITEM:getHeight()
	return self._normalState.contentHeight
end

function SPEEDUPITEM:affect( player )
	player.velocityY = self:getNSpeedUp()
end

function SPEEDUPITEM:removeSelf()
	self._normalState:removeSelf()
	self._actState:removeSelf()
end

return SPEEDUPITEM